package com.twu.biblioteca.menuoptions;

import com.twu.biblioteca.LibraryManager;

/**
 * Created by olga on 7/06/14.
 */
public class CheckOutBookOption extends MenuOption
{
    private static final String SUCCESS_MSG = "Thank you! Enjoy the book!";
    private static final String FAILURE_MSG = "That book is not available.";

    public CheckOutBookOption(UserDetailsHandler userDetailsHandler)
    {
        super("Check out a book", userDetailsHandler);
        requiresLogin = true;
    }

    public void action(LibraryManager libraryManager)
    {
        if( checkUserLogin() )
        {
            userDetailsHandler.printUserDetails();
            runOption(libraryManager);
        }
    }

    public void runOption( LibraryManager libraryManager )
    {
        getUserInputValues();
        libraryManager.setUserDetailsHandler(userDetailsHandler);
        super.printSuccessOrFailure(libraryManager.checkOutBook(getTitle(),getCreator(),getYear()), SUCCESS_MSG, FAILURE_MSG );
    }
}
